<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function getValueById(id) {
            return document.getElementById(id).value;
        }

        function isEmail(strEmail) {
            if ((strEmail.length > 128) || (strEmail.length < 6)) {
                return false;
            }
            var eFormat = /^[A-Za-z0-9+]+[A-Za-z0-9\.\_\-+]*@([A-Za-z0-9\-]+\.)+[^\.]+$/;
            return (strEmail.search(eFormat) == 0);
        }

        function validate() {
            var username = getValueById("uname");
            var pwd = getValueById("passwd");
            var email = getValueById("email");
            var pwdConfirm = getValueById("fpasswd");
            var fname = getValueById("fname");
            var frm = document.getElementById("mainForm");
            var isValid = true;
            var msg = "";

            // if (username == "" || pwd == "") {
            //     msg += "请确定用户名和密码输入是否正确。\n";
            //     //alert("请确定用户名和密码输入是否正确。")
            //     isValid = false;
            // }


            if (email == "" || !isEmail(email)) {
                msg += "请确定电子邮件输入是否正确。\n";
                //alert("请确定电子邮箱输入是否正确。")
                isValid = false;
            }

            if (username.length < 8) {
                msg += "用户名长度太短，至少8个字符！！\n";
                //alert("用户名长度太短，至少8个字符！！");
                isValid = false;
            }

            if (pwd.length < 6) {
                msg += "密码长度太短，至少6个字符！！\n"
                //alert("密码长度太短，至少6个字符！！");
                isValid = false;
            }

            if (pwd != pwdConfirm) {
                msg += "两次输入的密码必须一致！！\n"
                //alert("两次输入的密码必须一致！！");
                isValid = false;
            }

            if (typeof (Storage) != "undefined") {
                //是的! 支持 localStorage sessionStorage对象! //一些代码...
                msg += "支持 localStorage sessionStorage对象!\n"
            }
            else {
                //抱歉! 不支持web存储。 
                msg += "抱歉! 不支持web存储。\n ";
                isValid = false;
            }

            if (isValid) {
                localStorage.setItem("curucode", username);
                localStorage.setItem(username, fname);
                localStorage.setItem(username+"_p", pwd);
                frm.submit();
            } else {
                alert(msg);
            }

        }
    </script>
</head>

<body>
    <form id="mainForm" action="login.html" method="POST">
        <fieldset>
            <legend>用户注册信息</legend>
            <label for="uname">&emsp;&emsp;&emsp;用户名：</label>
            <input id="uname" type="text" />
            <br />
            <label for="ucode">&emsp;&emsp;&emsp;学&emsp;号：</label>
            <input id="ucode" type="text" />
            <br />
            <label for="fname">&emsp;&emsp;&emsp;姓&emsp;名：</label>
            <input id="fname" type="text" />
            <br />
            <label for="passwd">&emsp;&emsp;&emsp;密&emsp;码：</label>
            <input id="passwd" type="password" />
            <br />
            <label for="fpasswd">&emsp;&emsp;确认密码：</label>
            <input id="fpasswd" type="password" />
            <br />
            <label for="email">&emsp;&emsp;电子邮箱：</label>
            <input id="email" type="text" />
            <br />
            <label for="question">密码提示问题：</label>
            <input id="question" type="text" />
            <br />
            <label for="answer">密码提示答案：</label>
            <input id="answer" type="text" />
            <br />
            <input value="确认" type="button" onclick="validate()" />
            <input value="重置" type="reset" />
            <br />
        </fieldset>
    </form>
</body>

</html>